<?php
/**
 * @file $HeadURL: announcement.php $
 * @author $Author: DongJC (dongjianchang@haibao.com) $
 * @date $Date: 2015-3-25 10:59:25 $
 * @brief 
 */
namespace haibao\cms\business;

use \haibao\cms\data\Announcement as AnnouncementData; 

class Announcement extends \haibao\cms\business\Base{
	
	public static function addAnnouncement($model){
		self::checkOperation(self::FUNC_CODE_ANNOUNCEMENT_ADD);
		if(!isset($model->Title)){
			throw new BusinessException('请添加标题');
		}
		if(!isset($model->Summary)){
			throw new BusinessException('请添加内容');
		}
		$announcementData = new AnnouncementData();
		$announcementData->add($model);
		
		self::saveOperateHistory(self::FUNC_CODE_ANNOUNCEMENT_ADD, $model->toArray(false));
	}
	
	public static function updateAnnouncement($model){
		self::checkOperation(self::FUNC_CODE_ANNOUNCEMENT_EDIT);	
		if(!$model->Id){			
			throw new BusinessException('公告Id不能为空');
		}
		if(!isset($model->Title)){			
			throw new BusinessException('请添加标题');
		}
		if(!isset($model->Summary)){			
			throw new BusinessException('请添加内容');
		}
		$announcementData = new AnnouncementData();
		$announcementData->updateById($model->Id, $model);
		self::saveOperateHistory(self::FUNC_CODE_ANNOUNCEMENT_EDIT, $model->toArray(false));
	}
	
	public static function getModelById($announcementId){
		if(!$announcementId){
			return NULL;
		}
		$announcementData = new AnnouncementData();
		return $announcementData->getOneById($announcementId);
	}
	
	public static function getAnnouncementList($announcementFilter){
		$announcementData = new AnnouncementData();
		return $announcementData->getAll($announcementFilter);
	}
	
	public static function delAnnouncement($id){
		self::checkOperation(self::FUNC_CODE_ANNOUNCEMENT_DEL);
		if (!$id){
			throw new BusinessException('公告Id不能为空',self::DATA_EMPTY_FEATURE_ID);
		}
		$announcementData = new AnnouncementData();
		$announcementData->removeById($id);
		self::saveOperateHistory(self::FUNC_CODE_ANNOUNCEMENT_DEL, array($id));
	}
	
}
